 var app = getApp();
 var isclose = true;
 var getList = function() {
   var _this = this;
   var pageIndex = _this.data.currentPage;
   wx.request({
     url: app.globalData.domain + 'api/wxapp_get',
     data: {
       time: app.globalData.getTime(),
       page: pageIndex
     },
     method: 'GET',
     success: function(res) {
       if (pageIndex==1){//下拉刷新
         _this.setData({
           allActivity: res.data.project,
           isHideLoadMore: false,
           isLoading: false,
           allPages: res.data.allPages
         });
       }else{
         var tempArray = _this.data.allActivity;
         tempArray = tempArray.concat(res.data.project);
         _this.setData({
           allActivity: tempArray,
           isHideLoadMore: false,
           isLoading: false,
           allPages: res.data.allPages
         });
       }
       
        wx.hideNavigationBarLoading();
     }
   });
 };
 Page({
   data: {
     scrollTop: 100,

     isHideLoadMore: true,
     isLoading:false,
     allActivity: [], // 列表显示的数据源
     allPages: '',    // 总页数
     currentPage: 1,  // 当前页数  默认是1
     loadMoreData: '正在加载' 

   },
   upper: function(e) {},
   lower: function(e) {},
   scroll: function(e) {},
   tap: function(e) {},
   tapMove: function(e) {
     this.setData({
       scrollTop: this.data.scrollTop + 10
     })
   },
   detail: function(e) {
     var id = e.target.dataset.id;
     if (!id) {
       return;
     }
     wx.navigateTo({
       url: '/pages/detail/detail?id=' + id
     });
   },
   onPageScroll: function (e) { // 获取滚动条当前位置
    //  console.log(e.scrollTop)
     this.setData({
       scrollTop: e.scrollTop
     })
   },
   onPullDownRefresh: function() {
     console.info("refresh")

     var self = this;
     if (wx.pageScrollTo) {
       wx.pageScrollTo({
         scrollTop: 0//self.data.scrollTop-1
       })
     }
     setTimeout(function () {
       self.setData({
         currentPage: 1,
         loadMoreData: '正在加载'
       })
       getList.call(self);
     }, 300);


     
   },
   onLaunch:function(){
    
   },
   onHide:function(){
     isclose=false;
   },
   onUnload:function(){
     isclose = true;
   },
   onShow: function() {
     wx.showNavigationBarLoading();
     if(!isclose){
      //  getList.call(this);
       console.info("onShow")
       var self = this;
       self.onPullDownRefresh()
     }
     app.getUserInfo(function (userInfo) {
       console.log(userInfo);
     });
   },
   onReady: function() {
    
    
   },
   onLoad: function() {
     var date = new Date();
     this.setData({
       time: date.Format('yyyy-MM-dd'),
       refreshTime: date.toLocaleTimeString()
     })
     getList.call(this);
   },
   onShareAppMessage: function (res){
     if (res.from === 'button') {
       // 来自页面内转发按钮
       console.log(res.target)
     }
     return {
       title: '所有项目',
       path: '/pages/all/all',
       success: function (res) {
         console.log("转发成功")
       },
       fail: function (res) {
         console.log("转发失败")
       }
     }
   },

   onReachBottom: function () {
     console.log('加载更多');
     var self = this;
     // 当前页是最后一页
     if (self.data.currentPage == self.data.allPages) {
       self.setData({
         loadMoreData: '没有更多数据',
         isHideLoadMore: false,
         isLoading: true
       })
       return;
     }
     setTimeout(function () {
       console.log('上拉加载更多');
       var tempCurrentPage = self.data.currentPage;
       tempCurrentPage = tempCurrentPage + 1;
       self.setData({
         currentPage: tempCurrentPage,
         isHideLoadMore: false
       })
       getList.call(self);
     }, 300);

   },


 });


 Date.prototype.Format = function (fmt) {
   var o = {
     "M+": this.getMonth() + 1, //月份 
     "d+": this.getDate(), //日 
     "h+": this.getHours(), //小时 
     "m+": this.getMinutes(), //分 
     "s+": this.getSeconds(), //秒 
     "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
     "S": this.getMilliseconds() //毫秒 
   };
   if (/(y+)/.test(fmt))
     fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
   for (var k in o) {
     if (new RegExp("(" + k + ")").test(fmt)) {
       fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
     }
   }
   return fmt;
 }